//
//  SerceCollectionCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/4.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "ServeCollectionCell.h"

@interface ServeCollectionCell ()

@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UILabel *companyLabel;
@property (nonatomic, strong) UILabel *moneyLabel;


@end

@implementation ServeCollectionCell

-(void)setServeCollectionModel:(ServeCollectionModel *)serveCollectionModel
{
    _serveCollectionModel = serveCollectionModel;

    self.nameLabel.text = serveCollectionModel.pic;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:serveCollectionModel.design_name] placeholderImage:nil options:SDWebImageRetryFailed];
    self.moneyLabel.text = serveCollectionModel.price;
    self.companyLabel.text = serveCollectionModel.design_des;
    //缺少detailLabel.text
}

+ (ServeCollectionCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ServeCollectionCell";
    ServeCollectionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ServeCollectionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}
-(void)setServeGoodsDataModel:(ServeGoodsDataModel *)serveGoodsDataModel
{
    _serveGoodsDataModel = serveGoodsDataModel;
    
    self.nameLabel.text = serveGoodsDataModel.design_name;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:serveGoodsDataModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元",serveGoodsDataModel.price];
    self.companyLabel.text = serveGoodsDataModel.name;
    NSString *volumeNum = [NSString stringWithFormat:@"成交%@笔|",serveGoodsDataModel.volume];
    NSString *zongfenNum = [NSString stringWithFormat:@"服务评分：%@分|",serveGoodsDataModel.zongfen];
    NSString *distanceNum = [NSString stringWithFormat:@"%@km",serveGoodsDataModel.distance];
    self.detailLabel.text = [[volumeNum stringByAppendingString:zongfenNum] stringByAppendingString:distanceNum];
}

- (void)createSubView {
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(103), ScreenX375(71))];
    self.headImage.layer.cornerRadius = ScreenX375(5);
    self.headImage.clipsToBounds = YES;
//    self.headImage.image = [UIImage imageNamed:@"头部背景"];
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(126), ScreenX375(14), ScreenX375(160), ScreenX375(16))];
    self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.nameLabel.font = Kfont(14);
//    self.nameLabel.text = @"公司包装设计 / 商标设...";
    [self addSubview:self.nameLabel];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(126), ScreenX375(37), SCREEN_WIDTH - ScreenX375(139), ScreenX375(14))];
    self.detailLabel.textColor = REXADECIMALCOLOR(@"#999999");
    self.detailLabel.font = Kfont(12);
//    self.detailLabel.text = @"成交2243笔 | 服务评分：4.98分 | 15km";
    [self addSubview:self.detailLabel];
    
    self.companyLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(126), ScreenX375(73), ScreenX375(260), ScreenX375(14))];
    self.companyLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.companyLabel.font = Kfont(12);
//    self.companyLabel.text = @"森林包装设计";
    [self addSubview:self.companyLabel];
    
    self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(113), ScreenX375(70), ScreenX375(100), ScreenX375(22))];
    self.moneyLabel.textColor = ThemeColor;
    self.moneyLabel.font = Kfont(14);
    self.moneyLabel.textAlignment = NSTextAlignmentRight;
//    self.moneyLabel.text = @"100元";
    [self addSubview:self.moneyLabel];
    
    self.collctBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(31), ScreenX375(15), ScreenX375(19), ScreenX375(18))];
    [self.collctBtn setImage:[UIImage imageNamed:@"服务收藏-收藏"] forState:UIControlStateNormal];
    [self.collctBtn addTarget:self action:@selector(cancelConcernClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.collctBtn];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(101) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
    line.image = [UIImage imageNamed:@"虚线"];
    [self addSubview:line];
}

- (void)cancelConcern {
    if (_cancelConcernClick) {
        _cancelConcernClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation ServeCollectionModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id",
                                                                  }];
}

@end
